package com.kksoft.readcm.activity;

import java.util.Observable;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.Menu;

import com.kksoft.readcm.a.Appconfig;
import com.kksoft.readcm.objects.GlobalVar;
import com.kksoft.readcm.pro.R;

public class LoadingListActivity extends RilAppActivity
{
  private boolean a = true;

  static boolean a(LoadingListActivity loadinglistactivity)
  {
      return loadinglistactivity.f();
  }

  static void b(LoadingListActivity loadinglistactivity)
  {
      loadinglistactivity.e();
  }
  
  private void e()
  {
    this.u.postDelayed(new Runnable(){

		@Override
		public void run() {
			// TODO Auto-generated method stub
			if (!LoadingListActivity.a(LoadingListActivity.this))
		      LoadingListActivity.b(LoadingListActivity.this);
		}
    	
    }, 1000L);
  }

  private boolean f()
  {
	  if(this.a) 
	  {
          if(Appconfig.getThis().m())
          {
        	  this.a = false;
        	  Intent it = getIntent();
        	  if(it == null)
	          {
	              finish();
	              return true;
	          }
	          switch(it.getIntExtra("waitingForLoad", 0))
	          {
	          	default:
	          		return true;
	          	case 1:
	          		Intent intent = new Intent(this, ReaderActivity.class);
	  	          	intent.putExtra("item_url", it.getStringExtra("item_url"));
	  	          	if (intent!=null)
	  	          	{
	  	          		startActivity(intent);
	  	          		overridePendingTransition(0, 0);
	  	          	}

	  	          		finish();
	  	          return true;
	          	case 2:
	          		Intent intent2 = new Intent(this, EditItemActivity.class);
	          		intent2.putExtra("item_id", intent2.getIntExtra("item_id", 0));
		  	        if (intent2!=null)
	  	          	{
	  	          		startActivity(intent2);
	  	          		overridePendingTransition(0, 0);
	  	          	}
		  	      finish();
		  	      return true;
	          }
          }
          else return true;
          
	  }
	  else
	  {
		  return true;
	  }
  }

  protected final Drawable d_()
  {
    return getResources().getDrawable(R.drawable.splash_loading_bg);
  }

  public void onBackPressed()
  {
  }

  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    f();
  }

  public boolean onCreateOptionsMenu(Menu paramMenu)
  {
    return false;
  }

  protected void onRestart()
  {
    super.onRestart();
    f();
  }

  public void onResume()
  {
    super.onResume();
    if (!f())
      e();
  }

  protected final int getLayoutID()
  {
    return R.layout.activity_list_loading;
  }

  public void update(Observable paramObservable, Object paramObject)
  {
    if (this.a)
    {
    	final GlobalVar localh = GlobalVar.a(paramObject);
      if (localh != null)
      {
      runOnUiThread(new Runnable(){

		@Override
		public void run() {
			// TODO Auto-generated method stub
			switch (localh.a())
		    {
		    default:
		    case 1:
		    	LoadingListActivity.a(LoadingListActivity.this);
		    }
		}
    	  
      });
      super.update(paramObservable, paramObject);
      }
    }
  }
}